<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title> Insha - Css3 Responsive Sidebar Menu</title>

    <link href="../static/css/css2.css" rel="stylesheet">
    <link href='../static/css/boxicons.min.css' rel='stylesheet'>
    <link rel="stylesheet" href="../static/css/insha-style.css">

</head>

<body>

<div class="main" id="app">
    <div class="sidebar">
        <div class="logo_content">
            <div class="logo">
                <div class="logo_name">
                    <a href="#">
                        <i class='bx bxs-bank'></i>
                        银行业务管理系统
                    </a>
                </div>
            </div>
            <i class='bx bx-menu' id="toggle-menu-btn"></i>
        </div>
        <ul class="nav_list">

            <li>
                <a href="../online.html">
                    <i class='bx bx-yen'></i>
                    <span class="links_name">网上银行</span>
                </a>
                <span class="tooltip">网上银行</span>
            </li>
            <li>
                <a href="../counter.html">
                    <i class='bx bxs-user-account'></i>
                    <span class="links_name">银行柜面</span>
                </a>
                <span class="tooltip">银行柜面</span>
            </li>

        </ul>

    </div>
    <div class="home_content">
        <div class="text">银行柜面</div>
        <div class="rg_layout1">
            <div class="rg_left">
                <p>用户存款</p>
            </div>
            <div class="rg_center">
                <div class="rg_form">
                    <!--定义表单 form-->
                    <form action="#" method="">
                        <table id="tbe">
                            <tr>
                                <td class="td_left"><label for="idCard">银行卡号</label></td>
                                <td class="td_right"><input type="text" name="idCard" id="idCard"
                                                            placeholder="请输入银行卡号" v-model="idCard" @blur="ic()">
                                </td>
                            </tr>
                            <tr>
                                <td class="td_left"><label for="password">密码</label></td>
                                <td class="td_right"><input type="password" name="password" id="password"
                                                            placeholder="请输入银行卡密码" v-model="password"
                                                            @blur="pd1()"></td>
                            </tr>
                            <tr>
                                <td class="td_left"><label for="amount">存款金额</label></td>
                                <td class="td_right"><input type="text" name="amount" id="amount"
                                                            placeholder="金额数字首位不为0" v-model="amount"
                                                            @blur="am()"></td>
                            </tr>
                            <tr>
                                <td colspan="2" align="center"><input type="button" id="btn_sub" value="确认存款"
                                                                      @click="cm()"></td>
                            </tr>
                        </table>
                    </form>
                </div>
            </div>
            <button id="bn1" @click="back1()">返回</button>
        </div>
    </div>

</div>


<script src="../static/js/scripts.js"></script>
<script src="../static/js/vue.js"></script>
<script src="../static/js/axios.min.js"></script>
<script>
    const app = new Vue({
        el: "#app",
        data: {
            idCard: "",
            password: "",
            amount: "",
            balance: ""

        },
        methods: {
            back1() {
                location.href = "../counter.html"
            },
            cm() {
                if (this.idCard != "" && this.password != "" && this.amount != "") {
                    // confirm ("请确认存款金额")
                    let number=this.balance-0;
                    if(number<0){
                        alert("请输入正确的金额")
                        this.balance='';
                    }
                    if (confirm("请确认存款金额")) {
                        //存息请求
                        axios.get("http://localhost:8080/interestSettlementController/countInterestSettlement?data=0&bankNo=" + this.idCard).then(res => {
                            if (res.data.code == 200) {
                                //存款请求
                                axios({
                                    method: "POST",
                                    url: "http://localhost:8080/deposit/depositMoney",
                                    data: {
                                        bankNo: this.idCard,
                                        payPassword: this.password,
                                        balance: this.amount
                                    },
                                    Headers: {
                                        "Content-Type": "application/json"
                                    }
                                }).then(res => {
                                    let code = res.data.code;

                                    if (code !== 200) {

                                        alert(res.data.message)

                                    } else {
                                        alert("用户存款成功,账户余额为" + "【" + res.data.data + "】")
                                        window.location.reload();
                                    }
                                })
                            } else {
                                alert("系统故障，存款失败")
                            }
                        })


                    }
                } else {
                    alert("以上信息不能为空")
                }

            },
            ic() {
                if ((this.idCard.length != 16 && this.idCard.length != 17 && this.idCard.length != 19) && this.idCard != "") {
                    let rule = new RegExp("(^([1-9]{1})(\d{16}|\d{17}\d{19})$)")
                    if (rule.test(this.idCard) == false) {
                        alert("您的银行卡格式不正确，请重新输入")
                    }

                }
            },
            am() {
                if (this.amount.indexOf(0) == 0) {
                    alert("您的金额输入不正确")
                }
            },
            pd1() {
                if (this.password1 != "") {
                    let rule = new RegExp("(^[0-9]*$)")
                    if (rule.test(this.password1) == false) {
                        if (this.password1.length != 6) {
                            alert("您的密码长度不正确，请重新输入")
                            this.password1 = "";
                        }
                    }

                }

            }

        }
    })
</script>

</body>

</html>
